package com.zhaoxi.demo.filters;

import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Infor on 2017/07/05.
 */
public class TestFilter extends OncePerRequestFilter {

    public TestFilter() {
    }

    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {

        String requestType = httpServletRequest.getHeader("X-Requested-With");
        if (requestType != null && !requestType.equals("")) {
            System.out.println(httpServletRequest.getServletPath() + ": request is ajax");
        }

        filterChain.doFilter(httpServletRequest, httpServletResponse);

    }
}
